package com.kkd.springbootproject.Dao;

import com.kkd.springbootproject.pojo.Department;
import com.kkd.springbootproject.pojo.Emplyee;
import com.sun.javafx.util.TempState;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 14587
 * @date 2021/1/14 8:05
 */
@Repository
public class EmplyeeDao {
    //模拟数据库
    private static Map<Integer, Emplyee> employees=null;
    private DepartmentDao departmentDao;
    static {
        employees=new HashMap<Integer, Emplyee>();
        employees.put(101, new Emplyee(101,"dou","164123@qq.com",1,new Department(101,"教学部1")));
        employees.put(102, new Emplyee(102,"dou","164123@qq.com",1,new Department(101,"教学部1")));
        employees.put(103, new Emplyee(103,"dou","164123@qq.com",1,new Department(101,"教学部1")));
        employees.put(104, new Emplyee(104,"dou","164123@qq.com",1,new Department(101,"教学部1")));
    }

    private static Integer initId=105;
    //增加一个员工
    public void save(Emplyee emplyee,Integer departmentId){
        if (emplyee.getId()==null){
            emplyee.setId(initId++);
        }
        emplyee.setDepartment(departmentDao.getDepartmentById(departmentId));
        employees.put(emplyee.getId(),emplyee);
    }

    //获得全部员工信息
    public Collection<Emplyee> getEmployees(){
        return employees.values();
    }

    //通过id查询员工
    public Emplyee getEmployeeById(Integer id){
        return employees.get(id);
    }

    //通过id删除员工
    public void deleteEmployeeById(Integer id){
        employees.remove(id);
    }
}
